package org.miku.module.user;

import org.miku.db.SQLHelper;
import org.miku.sec.SecurityGuard;
import org.miku.tools.Tools;

public class RegisterManager extends BaseUserManager {
	
	public RegisterManager(SQLHelper sqlHelper) {
		super(sqlHelper);
	}
	
	public boolean detectUsername(String username) {
		boolean bRet = false;
		if(!Tools.isEmpty(username)) {
			bRet = userMgr.hasUser(username);
		}
		return bRet;
	}
	
	public String register(String username, String password,
			String secQuestion, String secAnswer) {
		String Ret = null;
		if(!Tools.isEmpty(username) && !Tools.isEmpty(password) &&
				!Tools.isEmpty(secQuestion) && !Tools.isEmpty(secQuestion)) {
			String pwd = SecurityGuard.DMB5(password);
			String regTime = Tools.getTime();
			
			UserInfo info = new UserInfo();
			info.setUsername(username);
			info.setPassword(pwd);
			info.setSecQuestion(secQuestion);
			info.setSecAnswer(secAnswer);
			info.setRegisterTime(regTime);
			
			userMgr.addUser(info);
		}
		return Ret;
	}
}
